// kafka/config.go
package kafka

import (
	"github.com/Shopify/sarama"
)

type Config struct {
	Brokers  []string
	Username string
	Password string
	Topic    string
}

func NewConfig(brokers []string, username, password, topic string) *Config {
	return &Config{
		Brokers:  brokers,
		Username: username,
		Password: password,
		Topic:    topic,
	}
}

func (c *Config) SaramaConfig() *sarama.Config {
	config := sarama.NewConfig()
	config.Producer.Return.Successes = true
	config.Version = sarama.V2_0_0_0

	if c.Username != "" && c.Password != "" {
		config.Net.SASL.Enable = true
		config.Net.SASL.User = c.Username
		config.Net.SASL.Password = c.Password
	}

	return config
}
